# 10.2.1 写入空文件
file_name = 'haha.txt'
with open(file_name, 'w') as file_object:
    file_object.write("hello")

# 10.2.2 写入多行
file_name = 'text_files\writetxt.txt'
with open(file_name, 'w') as file_object:
    file_object.write("hello\n")
    file_object.write("hello world\n")

# 10.2.3 附加到文件
file_name = 'text_files\writetxt.txt'
with open(file_name, 'a') as file_object:
    file_object.write("hello world\n")
    file_object.write("hello world\n")